<?php
/****
* 用户对活动的关注度\评分等
****/
class EventMarkModel extends Model{
    static private $_CONST=array(
        'MARK_UNKNOWN'=>0,
        'MARK_WISH'=>2,
        'MARK_TAKE'=>4,
        'MARK_DISLIKE'=>-1,
    );
    static public function C($name){
        return self::$_CONST[$name];
    }
    protected $tableName='event_mark';
    
    /****
    * @return 受影响的条数
    */
    public function takeEvent($uid, $eid, $data=array()){
        $map=array(
            'uid'=> $uid,
            'eid'=> $eid,
        );
        $data=$data+ $map;
        $this->where($map);
        if ($this->find()){
            $r= $this->where($map)->setField('take', self::C('MARK_TAKE'));
        } else{
            $data['take']= self::C('MARK_TAKE');
            $r= $this->data($data)->add();
        }
        if ($r){
            TimelineModel::factor('TYPE_TAKE', $uid, $eid, $data['title'])->add();
        }
        return $r;
    }
    public function wishEvent($uid, $eid, $data=array()){
        $map=array(
            'uid'=> $uid,
            'eid'=> $eid,
        );
        $data=$data+ $map;
        $this->where($map);
        if ($this->find()){
            $r= $this->where($map)->setField('wish', self::C('MARK_WISH'));
        } else{
            $data['wish']= self::C('MARK_WISH');
            $r= $this->data($data)->add();
        }
        if ($r){
            TimelineModel::factor('TYPE_WISH', $uid, $eid, $data['title'])->add();
        }
        return $r;
    }
}
?>